package render.display
{
	import flash.display.Stage;
	import flash.display3D.Context3D;
	import flash.display3D.IndexBuffer3D;
	import flash.display3D.Program3D;
	import flash.display3D.VertexBuffer3D;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import flash.geom.Matrix3D;
	import flash.geom.Vector3D;
	
	import render.materials.textures.Texture2D;

	[Event(name="click", type="flash.events.MouseEvent")]
	[Event(name="mouseDown", type="flash.events.MouseEvent")]
	[Event(name="mouseUp", type="flash.events.MouseEvent")]
	[Event(name="mouseOver", type="flash.events.MouseEvent")]
	[Event(name="mouseOut", type="flash.events.MouseEvent")]
	public class RenderObject extends EventDispatcher
	{
		/**
		 *本地矩阵 
		 */		
		protected var _localMatrix:Matrix3D = new Matrix3D();
		protected var _stage:Stage;
		/**
		 *Context3D 对象 
		 */		
		protected var _context3D:Context3D;
		protected var _program3D:Program3D;
		protected var _width:Number = 1;
		protected var _height:Number = 1;
		protected var _rotation:Number = 0;
		protected var _x:Number = 0;
		protected var _y:Number = 0;
		protected var _scaleX:Number = 1.0;
		protected var _scaleY:Number = 1.0;
		protected var _texture2D:Texture2D;
		protected var _vertexBuffer3D:VertexBuffer3D;
		protected var _indexBuffer3D:IndexBuffer3D;
		protected var _defaultVertexData:Vector.<Number>=new Vector.<Number>();
		protected var _mouseEnabled:Boolean;
		public var vx:Number;
		public var vy:Number;
		
		public function RenderObject()
		{

		}
		
		public function render():void
		{
		}

		/**
		 *鼠标事件处理 
		 * @param mouseEventType 事件名称
		 * @param mousePosition 鼠标相对于舞台的点
		 * 
		 */		
		public function processMouseEvent(mouseEventType:String, mousePosition:Vector3D):void
		{
			switch(mouseEventType)
			{
				case MouseEvent.CLICK:
//					dispatchEvent(new MouseEvent(mouseEventType, ));
					break;
			}
		}
		
		/**
		 *本地矩阵
		 */
		public function get localMatrix():Matrix3D
		{
			return _localMatrix;
		}

		/**
		 * @private
		 */
		public function set localMatrix(value:Matrix3D):void
		{
			_localMatrix = value;
		}

		/**
		 *材质贴图 
		 */
		public function get texture2D():Texture2D
		{
			return _texture2D;
		}

		/**
		 * @private
		 */
		public function set texture2D(value:Texture2D):void
		{
			_texture2D = value;
		}

		public function get vertexBuffer3D():VertexBuffer3D
		{
			return _vertexBuffer3D;
		}

		public function set vertexBuffer3D(value:VertexBuffer3D):void
		{
			_vertexBuffer3D = value;
		}

		public function get indexBuffer3D():IndexBuffer3D
		{
			return _indexBuffer3D;
		}

		public function set indexBuffer3D(value:IndexBuffer3D):void
		{
			_indexBuffer3D = value;
		}

		public function get width():Number
		{
			return _width;
		}

		public function set width(value:Number):void
		{
			_width = value;
		}

		public function get height():Number
		{
			return _height;
		}

		public function set height(value:Number):void
		{
			_height = value;
		}

		public function get rotation():Number
		{
			return _rotation;
		}

		public function set rotation(value:Number):void
		{
			_rotation = value;
		}

		public function get x():Number
		{
			return _x;
		}

		public function set x(value:Number):void
		{
			_x = value;
		}

		public function get y():Number
		{
			return _y;
		}

		public function set y(value:Number):void
		{
			_y = value;
		}

		public function get scaleX():Number
		{
			return _scaleX;
		}

		public function set scaleX(value:Number):void
		{
			_scaleX = value;
		}

		public function get scaleY():Number
		{
			return _scaleY;
		}

		public function set scaleY(value:Number):void
		{
			_scaleY = value;
		}

		/**
		 *Context3D 对象 
		 */
		public function get context3D():Context3D
		{
			return _context3D;
		}

		/**
		 * @private
		 */
		public function set context3D(value:Context3D):void
		{
			_context3D = value;
		}

		public function get program3D():Program3D
		{
			return _program3D;
		}

		public function set program3D(value:Program3D):void
		{
			_program3D = value;
		}

		public function get stage():Stage
		{
			return _stage;
		}

		public function set stage(value:Stage):void
		{
			_stage = value;
		}
		
		public function dispose():void
		{
			_context3D=null;
			_program3D=null;
			_localMatrix=null;
			if(_texture2D)
			{
				_texture2D.dispose();
				_texture2D=null;
			}
			if(_vertexBuffer3D)
			{
				_vertexBuffer3D.dispose();
				_vertexBuffer3D=null;
			}
			if(_indexBuffer3D)
			{
				_indexBuffer3D.dispose();
				_indexBuffer3D=null;
			}
			_defaultVertexData=null;
		}

		public function get mouseEnabled():Boolean
		{
			return _mouseEnabled;
		}

		public function set mouseEnabled(value:Boolean):void
		{
			_mouseEnabled = value;
		}

	}
}